package com.gwq.computedUtils;

import lombok.Data;

import java.util.Random;

@Data
public abstract class NewBinaryOperation {

    static final int UPPER = 100;
    static final int LOWER = 0;

    private int left_operand = 0,right_operand=0;
    private String operator = "+";
    private int value = 0;


    protected void generateBinaryOperation(String anOperator){
        int left,right,result;
        Random random = new Random();
        left = random.nextInt(UPPER+1);
        do{
            right = random.nextInt(UPPER+1);
            result = calculate(left,right);
        }while (!(checkingCalculation(result)));
        left_operand = left;
        right_operand = right;
        operator = anOperator;
        value = result;
    }

    abstract boolean checkingCalculation(int anInteger);
    abstract int calculate(int left,int right);



    public boolean equals(NewBinaryOperation binaryOperation){
        return left_operand == binaryOperation.getLeft_operand()&
                right_operand == binaryOperation.getRight_operand()&
                operator == binaryOperation.getOperator();
    }

    public void unsafeConstructor(int left,int right,int value,String op){
        this.setLeft_operand(left);
        this.setRight_operand(right);
        this.setValue(value);
        this.setOperator(op);
    }


    public String toString(){
        return left_operand+""+operator+""+right_operand;
    }

    public String asString(){
        return left_operand+""+operator+""+right_operand+"=";
    }

    public String fullString(){
        return left_operand+""+operator+""+right_operand+"="+value;
    }


}





